/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  javafx.event.EventHandler
 *  javafx.fxml.FXMLLoader
 *  javafx.scene.Parent
 *  javafx.scene.Scene
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Stage
 *  javafx.stage.WindowEvent
 */
package com.gys.controller.media;

import com.gys.controller.media.PlayerController;
import java.io.IOException;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class SimpleMediaPlayer
extends AnchorPane {
    private static SimpleMediaPlayer simpleMediaPlayer;
    private PlayerController controller;

    public PlayerController getController() {
        return this.controller;
    }

    private SimpleMediaPlayer(String mediaUrl) {
        try {
            FXMLLoader fxmlloader = new FXMLLoader(((this)).getClass().getResource("/fxml/media/Player.fxml"));
            Parent root = (Parent)fxmlloader.load();
            this.controller = (PlayerController)fxmlloader.getController();
            this.getChildren().add(root);
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void setSize(int width, int height) {
        if (simpleMediaPlayer.getController().getPopup()) {
            return;
        }
        simpleMediaPlayer.getController().setMediaPlayer(width, height);
    }

    public static SimpleMediaPlayer newInstance(String mediaUrl) {
        return SimpleMediaPlayer.newInstance(mediaUrl, 600, 400);
    }

    public static SimpleMediaPlayer newInstance(String mediaUrl, int width, int height) {
        simpleMediaPlayer = new SimpleMediaPlayer(mediaUrl);
        simpleMediaPlayer.getController().start(mediaUrl, false, width, height);
        return simpleMediaPlayer;
    }

    public static SimpleMediaPlayer popup(String mediaUrl) {
        return SimpleMediaPlayer.popup(mediaUrl, 800, 600);
    }

    public static SimpleMediaPlayer popup(String mediaUrl, int width, int height) {
        simpleMediaPlayer = new SimpleMediaPlayer(mediaUrl);
        simpleMediaPlayer.getController().start(mediaUrl, true, width, height);
        Scene scene = new Scene((Parent)simpleMediaPlayer, (double)width, (double)height);
        simpleMediaPlayer.getController().setScene(scene);
        Stage primaryStage = new Stage();
        primaryStage.setTitle("Media Player");
        primaryStage.setScene(scene);
        primaryStage.setOnCloseRequest((EventHandler)new EventHandler<WindowEvent>(){

            public void handle(WindowEvent event) {
                simpleMediaPlayer.getController().destroy();
            }
        });
        primaryStage.show();
        return simpleMediaPlayer;
    }
}

